<?php 
class Smsali{
	private $sign = '灵芝普惠商城'; //初源直供
	private $tpl_reg = 'SMS_93780045';
	private $tpl_find = 'SMS_93780044';
	private $key = 'bce793a43c5f9ea2';
	private $secret = '302a19b0f0e1dda7';
	
	
	/**
	 * 统一发送短信函数
	 * @param string $phone  电话
	 * @param int $type      短信类型  1-注册  2-找回密码
	 * @param mixed $content 内容
	 */
	public function sendgxmsg($phone,$type,$code){
		switch ($type){
			case 1:  $res=$this->register($phone, $code);break;
			case 2:	 $res=$this->findpwd($phone, $code);break;
		}
			
		return $res;
	}
	
	
	public function findpwd($phone, $code){
		$data = array('code'=>$code);
		return $this->send($phone, $this->tpl_find, $data);
	}
	
	/**
	 * 发送注册验证码
	 * @param string $phone	手机号码
	 */
	public function register($phone, $code){
		$data = array('code'=>$code);
		return $this->send($phone, $this->tpl_reg, $data);
	}
	
	/**
	 * 阿里云短信发送函数
	 */
	private function send($phone, $tpl, $data){
		$param = array(
				'phone' => $phone,
				'sign' => $this->sign,
				'tpl' => $tpl,
				'key' => $this->key,
				'secret' => $this->secret,
				'param' => $data
		);
		$url = http_build_query($param);
		$url = "http://www.ewmfwsy.com/api/tool/smsali?".$url;
		
		$string = file_get_contents($url);

		if(!$string) return false;
		$result = json_decode($string, true);
		if(!$result || $result['code'] < 1) return false;
	
		return true;
	}
}
?>